package com.hmall.user.web;

import com.hmall.user.pojo.Address;
import com.hmall.user.service.IAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    /**
     * 根据地址id查询地址信息
     */
    @GetMapping("{addressId}")
    public Address findAddressById(@PathVariable("addressId") Long id) {
        return addressService.getById(id);
    }

    /**
     * 根据用户id查询地址列表
     */
    @GetMapping("/uid/{userId}")
    public List<Address> findAddressByUserId(@PathVariable("userId") Long userId) {
        List<Address> list = addressService.getByUserId(userId);
        System.out.println(list);
        return list;
    }
    //添加地址
    @PostMapping
    public Address addAddress(@RequestBody Address address) {
        return addressService.add(address);
    }
    @DeleteMapping("{addressId}")
    public void deleteAddressById(@PathVariable("addressId") Long id) {
        addressService.deleteById(id);
    }
}
